#include "FileLogger.h"
#include <stdio.h>

namespace util {

FileLogger::FileLogger(std::string logFileName, std::string errorFileName) :
	Logger::Logger() {
	this->logOutput = fopen(logFileName.c_str(), "a");
	this->errorOutput = fopen(errorFileName.c_str(), "a");
	if (this->logOutput == NULL) {
		std::string message("ERROR en FileLogger: no se pudo abrir el archivo "
				+ logFileName);
		printf("%s", message.c_str());
	}
	if (this->errorOutput == NULL) {
		std::string message("ERROR en FileLogger: no se pudo abrir el archivo "
				+ errorFileName);
		printf("%s", message.c_str());
	}
}

FileLogger::~FileLogger() {
	fclose(this->logOutput);
	fclose(this->errorOutput);
}

void FileLogger::error(std::string message) {
	this->toFile(message, "ERROR", this->errorOutput);
}

void FileLogger::warn(std::string message) {
	this->toFile(message, "WARN", this->errorOutput);
}

void FileLogger::info(std::string message) {
	this->toFile(message, "INFO", this->logOutput);
}
void FileLogger::toFile(std::string message, std::string type, FILE* output) {
	fputs(this->buildMessage(message, type).c_str(), output);
}
}
